package eu.news.data.hibernate.pojo;

import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import eu.news.data.pojo.Attachment;
import eu.news.data.pojo.Comment;
import eu.news.data.pojo.News;
import eu.news.data.pojo.Operator;
import eu.news.data.pojo.Picture;
import eu.news.data.pojo.Sort;

/**
 * 新闻实体
 * 
 * @author WZZ
 * 
 */
@Entity
@Table(name = "news")
public class HB_News extends News implements java.io.Serializable{
	/**
	 * serialVersionUID
	 */
	private static final long serialVersionUID = 7064630969461155912L;

	/**
	 * 代理主键
	 */
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	int id;

	/**
	 * 新闻标题,not null
	 */
	@Column(name = "title", nullable = false)
	String title;

	/**
	 * 正文,null
	 */
	@Column(name = "content", columnDefinition = "text")
	String content;

	/**
	 * 分类,FK->Sort
	 */
	@ManyToOne(cascade = CascadeType.ALL, targetEntity = HB_Sort.class, fetch = FetchType.LAZY)
	@JoinColumn(name = "sort_id")
	HB_Sort sort;

	/**
	 * 操作者，新闻来源,not null,FK->Operator
	 */
	@ManyToOne(cascade = CascadeType.ALL, targetEntity = HB_Operator.class, fetch = FetchType.LAZY)
	@JoinColumn(name = "operator_id", nullable = false)
	HB_Operator operator;

	/**
	 * 评论,FK<-Comment
	 */
	@OneToMany(cascade = CascadeType.ALL, mappedBy = "news", fetch = FetchType.LAZY)
	Set<HB_Comment> comments = new HashSet<HB_Comment>();

	/**
	 * 附件
	 */
	@OneToMany(cascade = CascadeType.ALL, mappedBy = "news", fetch = FetchType.LAZY)
	Set<HB_Attachment> attachs = new HashSet<HB_Attachment>();

	/**
	 * 图片
	 */
	@OneToMany(cascade = CascadeType.ALL, mappedBy = "news", fetch = FetchType.LAZY)
	Set<HB_Picture> pictures = new HashSet<HB_Picture>();

	Date time;

	@Column(columnDefinition = "int", nullable = false)
	int state;

	/**
	 * 浏览次数
	 */
	@Column(name = "view_count")
	int view = 0;

	/**
	 * 新闻类型
	 */
	@Column(nullable=false)
	int type = 0;
	
	public HB_News() {
	};

	public HB_News(String title, HB_Sort sort, HB_Operator operator) {
		super();
		this.title = title;
		this.sort = sort;
		this.operator = operator;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public Sort getSort() {
		return sort;
	}

	public void setSort(Sort sort) {
		this.sort = (HB_Sort) sort;
	}

	public HB_Operator getOperator() {
		return operator;
	}

	public void setOperator(Operator operator) {
		this.operator = (HB_Operator) operator;
	}

	public Set<? extends Comment> getComments() {
		return comments;
	}

	@SuppressWarnings("unchecked")
	public void setComments(Set<? extends Comment> comments) {
		this.comments = (Set<HB_Comment>) comments;
	}

	public int getView() {
		return view;
	}

	public void setView(int view) {
		this.view = view;
	}

	public Date getTime() {
		return time;
	}

	public void setTime(Date time) {
		this.time = time;
	}

	public int getState() {
		return state;
	}

	public void setState(int state) {
		this.state = state;
	}

	public Set<? extends Attachment> getAttachs() {
		return attachs;
	}

	@SuppressWarnings("unchecked")
	public void setAttachs(Set<? extends Attachment> attachs) {
		this.attachs = (Set<HB_Attachment>) attachs;
	}

	public Set<? extends Picture> getPictures() {
		return pictures;
	}

	@SuppressWarnings("unchecked")
	public void setPictures(Set<? extends Picture> pictures) {
		this.pictures = (Set<HB_Picture>) pictures;
	}

	public int getType() {
		return type;
	}

	public void setType(int type) {
		this.type = type;
	}

}
